requireJS(['constant', 'site', 'handlebars'], function (Constant, site, Handlebars) {

    var url = {
        editAdmin: "manager/editAdmin.do",
        updateAdminInfo: "manager/updateAdminInfo.do"
    }

    var saved;
    site.send({
        url: url.editAdmin,
        data: {
            type: '2'
        },
        callback: function (data) {
            data = JSON.parse(data);
            if (data.type == 1) {
                if (data.content) {
                    var source = $("#adminInforma_content_tpl").html();
                    var template = Handlebars.compile(source);
                    var html = template(data);
                    $("#adminInforma_content").html(html);

                    saved = data.content;


                    $('.update').on('click', function () {
                        var data = {
                            id: saved.id,
                            rid: saved.rid,
                            rname: saved.rname,
                            d_name: saved.d_name,
                            departmentId: saved.did,
                            parentId0: saved.parentId0,
                            systemcode: JSON.parse(localStorage.getItem('content')).admin.systemcode
                        };
                        Constant.fn.formParam('.public-bgContent', data);
                        if (!data.username) {
                            Constant.fn.Message('I', '请输入用户名');
                            return;
                        }
                        if (!data.realName) {
                            Constant.fn.Message('I', '请输入真实姓名');
                            return;
                        }
                        if (!data.empno) {
                            Constant.fn.Message('I', '请输入员工号');
                            return;
                        }
                        if (!data.telephone) {
                            Constant.fn.Message('I', '请输入手机号');
                            return;
                        }
                        if (!Constant.reg.phone.test(data.telephone)) {
                            Constant.fn.Message('I', '手机号码格式有误')
                            return;
                        }
                        if (!data.mail) {
                            Constant.fn.Message('I', '请输入邮箱');
                            return;
                        }
                        if (!Constant.reg.email.test(data.mail)) {
                            Constant.fn.Message('I', '邮箱格式有误')
                            return;
                        }
                        site.send({
                            url: url.updateAdminInfo,
                            data: data,
                            callback: function (data) {
                                data = JSON.parse(data);
                                if (data.type == 1) {
                                    Constant.fn.Message("T", data.msg);
                                }
                                else {
                                    Constant.fn.Message("F", data.msg);
                                }
                            }
                        })
                    })
                }
            } else {
                Constant.fn.Message('F', data.msg)
            }
        }
    })
})